<div id="shares" class="pane-content">
	<div class="tb-all-trade">
		<table id="tradeRecordsIndex">
			<thead>
				<tr>
					<th class="time2">
						<a rel-value="" rel="orderBy" class="ico-order  desc " href="javascript:;">时间</a>
					</th>
					<th class="url">分享站点的URL</th>
					<th class="info">发布的消息</th>
					<th class="coupon">得到的优惠</th>
					<th class="expire">过期时间</th>
				</tr>
			</thead>
			<tbody>
				<?php
					require_once("dao\db.php");
					require_once("dao\coupon_dao.php");
					require_once("dao\shop_tactics_dao.php");
					$user_id = 1;
					$coupon_list = CouponDAO::getCoupons($user_id);
					if ($coupon_list) :
						foreach ($coupon_list as $coupon) :
				?>
				<tr>
					<td class="time2"> <?php echo $coupon["create_time"]; ?> </td>
					<td class="url"> 
						<?php 
							echo '<a href="' . $coupon["product_url"]. '">';
							echo $coupon["product_url"];
							echo '</a>';
						?> 
					</td>
					<td class="info"> <?php echo $coupon["message"]; ?> </td>
					<td class="coupon"> <?php echo $coupon["coupon_des"]; ?> </td>
					<td class="expire"> 
						<?php 
							$shop_tactics_id = $coupon["shop_tactics_id"];
							$shop_tactics = ShopTacticsDao::getShopTactics($shop_tactics_id);
							if ($shop_tactics) {
								echo $shop_tactics["expire"];
							}
						?> 
					</td>
				</tr>
				<?php 
					endforeach; 
					endif;
				?>
			</tbody>
		</table>
	</div>
	
	<!-- 分页 -->
	<div class="page page-nobg">
		<?php
			$message_num = count($coupon_list);
			$message_num_per_page = 10;
			$cur_page = $_REQUEST["page"];
			if($cur_page == null) $cur_page = 1; 

			//页码计算： 
			$page_num = ceil($message_num/$message_num_per_page); 
			$cur_page = min($page_num,$cur_page); 
			$pre_page = ($cur_page <=0 ? 0 : $cur_page - 1);
			$next_page = ($cur_page >= $page_num ? 0 : $cur_page + 1); //下一页 
			$first_count = ($cur_page - 1) * $message_num_per_page; 
			
			//开始分页导航条代码： 
			$pagenav = "显示第 <B>".($message_num ? ($first_count+1):0)."</B>-<B>".min($first_count + $message_num_per_page,$message_num)."</B> 条记录，共 $message_num 条记录"; 
			$pagenav .= " <a href='$url?page=1'>首页</a> "; 
			if($pre_page) $pagenav.=" <a href='$url?page=$pre_page'>前页</a> "; else $pagenav.=" 前页 "; 
			if($next_page) $pagenav.=" <a href='$url?page=$next_page'>后页</a> "; else $pagenav.=" 后页 "; 
			$pagenav .= " <a href='$url?page=$page_num'>尾页</a> "; 
			
			//下拉跳转列表，循环列出所有页码： 
			$pagenav .= "　到第 <select name='topage' size='1' onchange='window.location=\"$url?page=\"+this.value'>\n"; 
			for ($i = 1; $i <= $page_num; $i++) { 
				if($i == $cur_page) $pagenav .= "<option value='$i' selected>$i</option>\n"; 
				else $pagenav .= "<option value='$i'>$i</option>\n"; 
			} 
			$pagenav .= "</select> 页，共 $page_num 页"; 
			echo '<span class="page-link">' . $pagenav . '</span>'; 
		?>
	</div>
</div>